<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // get请求
    var xhr = new XMLHttpRequest();
    // xhr.open('get' , url , true);
    xhr.open('get' , url + '?' + params , true);
    xhr.send();
    xhr.onreadystatechange = function(){
      if(xhr.readyState == 4 && xhr.status == 200){
        console.log(xhr.responseText)
      }
    }

    // post请求
    var xhr = new XMLHttpRequest();
    xhr.open('post' , url , true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.send('数据名1 = 数据值1 & 数据名2 = 数据值2');
    xhr.onreadystatechange = function(){
      if(xhr.readyState == 4 && xhr.status == 200){
        console.log(xhr.responseText);
      }
    }


    // 默写代码-- get请求
    // var xhr = new XMLHttpRequest();
    // xhr.open('get' , url ,true)
    // xhr.send()
    // xhr.onreadystatechange = function (){
    //   if(xhr.readyState == 4 && xhr.status == 200){
    //     let data = xhr.responseText
    //   }
    // }


    // 默写代码 --- post请求
    // var xhr = new XMLHttpRequest()
    // xhr.open('post' , url , true)
    // xhr.setRequestHeader('Content-Type' , 'application/x-www-form-urlencoded')
    // xhr.send(params)
    // xhr.onreadystatechange = function(){
    //   if(xhr.readyState == 4 && xhr.status == 200){
    //     let data = xhr.responseText
    //   }
    // }
    
  </script>
</body>
</html>